﻿/*
Detect ID 
Time Limit:1000MS  Memory Limit:32768K

  
Description:
You know everyone is assigned an id when he is born in our country. It is an 18-digit or 16-digit string.
It has something to do with your resident place, birthday and others. 

In some place, the id has the form: "YYYYMMDDCCCC"

YYYY are the year.

For males, MM is a two-digit number of the mm, i.e., a number between 01 and 12, inclusive.

For females, MM is the number of the mm increased by 50, i.e., a number between 51 and 62, inclusive.

DD is a two digit number of the day in the mm.

CCCC are four arbitrary digits that are used both as a checksum and as a way to distinguish 
between different people born on the same day.
The checksum property works as follows: 
the digits CCCC must be chosen in such a way that the entire 12-digit number is divisible by eleven (11).
Input:
The input will be multiply cases. each case will be a 12-digit string as an id. 
Output:
Firstly, output the case order. Then if the id is valid output “Yes” else “No” 
Sample Input:
198104121237
198134120005
200411131237
Sample Output:
Case 1: Yes
Case 2: No
Case 3: No
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
int main()
{
	static const int months[] =
	{
		31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
	};

	char line[13];
	unsigned n = 0U;

	while (gets(line))
	{
		//puts(line);

		int sum = 0;
		for (size_t i = 0; line[i]; ++i)
		{
			if (i & 0x1)
				sum -= line[i];
			else
				sum += line[i];
		}
		bool valid = false;
		if (0 == sum % 11)
		{
			int mm = (line[4] - '0') * 10 + (line[5] - '0');
			if (mm >= 51)
				mm -= 50;
			if (mm >= 1 && mm <= 12)
			{
				int dd = (line[6] - '0') * 10 + (line[7] - '0');
				int month_day = months[mm - 1];
				if (2 == mm)
				{
					int yy = (line[0] - '0') * 1000 +
						(line[1] - '0') * 100 +
						(line[2] - '0') * 10 +
						(line[3] - '0');
					int is_leap = (0 == yy % 4 && 0 != yy % 100) ||
						(0 == yy % 400);
					month_day += is_leap;
				}
				if (dd >= 1 && dd <= month_day)
				{
					valid = true;
				}
			}
		}	
		++n;	
		if (valid)
			printf("Case %d: Yes\n", n);
		else
			printf("Case %d: No\n", n);
	}

	return EXIT_SUCCESS;
}
/*
int main()
{
static const int months[]={31,28,31,30,31,30,31,31,30,31,30,31};

  char line[12];
  unsigned n = 0U;
		
		  while (gets(line))
		  {
		  //puts(line);
		  
			int sum = 0;
			for (size_t i = 0; line[i]; ++i)
			{
			if (i & 0x1)
			sum -= line[i];
			else
			sum += line[i];
			}
			//	printf("%d\n", sum);
			bool valid=false;
			if (0==sum % 11)
			{
			char tmp=line[4];
			line[4]='\0';
			int yy = atoi(line);
			line[4]=tmp;
			
			  //printf("%d\n", yy);
			  
				tmp=line[6];
				line[6] = '\0';
				int mm = atoi(line + 4);
				if(mm >= 51)
				mm-=50;
				line[6]=tmp;
				//	printf("%d\n", mm);
				
				  if (mm >= 1 && mm <= 12 )	
				  {			
				  tmp=line[8];
				  line[8] = '\0';
				  int dd = atoi(line + 6);
				  line[8]=tmp;
				  
					//	printf("%d\n", dd);
					
					  int month_day=months[mm-1];
					  if(2==mm)
					  {
					  int is_leap = (0 == yy % 4 && 0 !=yy % 100) ||
					  (0 == yy % 400);
					  month_day+=is_leap;
					  }
					  //	printf("%d\n", month_day);
					  
						if(dd>=1 && dd<=month_day)
						{
						valid=true;
						}
						}
						}	
						++n;	
						if(valid)			
						printf("Case %d: Yes\n", n);
						else
						printf("Case %d: No\n", n);
						
						  }
						  
							return EXIT_SUCCESS;
}
*/
